home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / shazam.exe / GEDITOR.IMP < prev    next >
Text File  |  1992-09-01  |  18KB  |  494 lines

  1.    {*******************************************************************
  2.  
  3.    GEDITOR.IMP
  4.  
  5.    *******************************************************************}
  6.    {|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  7.  
  8.    EDITOR-SPECIFIC
  9.  
  10.    |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||}
  11.    {===================================================================
  12.  
  13.    EXTENT - return "cascaded" extent of current or first TWindow
  14.  
  15.    ===================================================================}
  16. procedure FirstExtent ( VAR R : TRect ) ;
  17. begin
  18.    DeskTop^.GetExtent ( R ) ;
  19.    if Desktop^.Current = NIL then EXIT ;
  20.    if not Desktop^.Current^.GetState ( sfVisible ) then EXIT ;
  21.    Desktop^.Current^.GetBounds ( R ) ;
  22.    if R.B.X - R.A.X > MinWinSize.X then
  23.       inc ( R.A.X ) ;
  24.    if R.B.Y - R.A.Y > MinWinSize.Y then
  25.       inc ( R.A.Y ) ;
  26. end ;
  27.    {===================================================================
  28.  
  29.    EXTENT - return "cascaded" extent of current or first TEditWindow
  30.  
  31.    ===================================================================}
  32. procedure FirstExtentEd ( VAR R : TRect ) ;
  33.    {-------------------------------------------------------------------
  34.    CURRENT
  35.    -------------------------------------------------------------------}
  36. function Test ( P : PView ) : boolean ; FAR ;
  37. begin
  38.    Test                      := FALSE ;
  39.    if TypeOf ( P^ ) <> TypeOf ( TEditWindow ) then EXIT ;
  40.    with PEDITWINDOW ( P )^.Editor^ do
  41.    begin
  42.       if not P^.GetState ( sfVisible ) then EXIT ;
  43.       P^.GetBounds ( R ) ;
  44.       Test                   := TRUE ;
  45.       if R.B.X - R.A.X > MinWinSize.X then
  46.          inc ( R.A.X ) ;
  47.       if R.B.Y - R.A.Y > MinWinSize.Y then
  48.          inc ( R.A.Y ) ;
  49.    end ;
  50. end ;
  51.    {- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  52.    PROCESS
  53.    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -}
  54. begin
  55.    DeskTop^.GetExtent ( R ) ;
  56.    Desktop^.FirstThat ( @Test ) ;
  57. end ;
  58.    {===================================================================
  59.  
  60.    NUMBER
  61.  
  62.    ===================================================================}
  63. function WinNumExist ( WinNum : integer ) : boolean ;
  64.    {-------------------------------------------------------------------
  65.    -------------------------------------------------------------------}
  66. function Test ( P : PView ) : boolean ; FAR ;
  67. begin
  68.    Test                      := FALSE ;
  69.    if not Selectable ( P ) then EXIT ;
  70.    Test                      := WinNum = PWINDOW ( P )^.Number ;
  71. end ;
  72.    {- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  73.    PROCESS
  74.    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -}
  75. begin
  76.    WinNumExist               := Desktop^.FirstThat ( @Test ) <> NIL ;
  77. end ;
  78.    {===================================================================
  79.  
  80.    NUMBER
  81.  
  82.    ===================================================================}
  83. function NextWinNum : integer ;
  84. var
  85.    i                         : integer ;
  86. begin
  87.    for i := 1 to 9 do
  88.       if not WinNumExist ( i ) then
  89.       begin
  90.          NextWinNum          := i ;
  91.          EXIT ;
  92.       end ;
  93.    NextWinNum                := wnNoNumber ;
  94. end ;
  95.    {===================================================================
  96.  
  97.    Opens a window, with choice of whether visible.
  98.    Sets "AutoIndent" on.  If NewEdit, set wrap & right margin.
  99.  
  100.    ===================================================================}
  101. function OpenEditor ( FileName : FNameStr ;
  102.                       Visible : boolean ) : PEditWindow ;
  103. var
  104.    P                         : PView ;
  105.    R                         : TRect ;
  106. begin
  107.    OpenEditor                := NIL ;
  108.    if Visible then
  109.       FirstExtentEd ( R )
  110.    else
  111.       DeskTop^.GetExtent ( R ) ;
  112.    P                         := Application^.ValidView (
  113.                                 New ( PEditWindow ,
  114.                                 Init ( R , FileName, NextWinNum ) ) ) ;
  115.    if P = NIL then EXIT ;
  116.    with PEDITWINDOW ( P )^ do
  117.    begin
  118.       if not Visible then
  119.          Hide ;
  120.       Editor^.AutoIndent     := TRUE ;
  121. {$IFDEF newedit }
  122.       Editor^.Word_Wrap      := Default_Word_Wrap ;
  123.       Editor^.Right_Margin   := Default_Line_Length ;
  124. {$ENDIF }
  125.    end ;
  126.    DeskTop^.Insert ( P ) ;
  127.    OpenEditor                := PEDITWINDOW ( P ) ;
  128. end ;
  129.    {|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  130.  
  131.    SAVE/CLOSE
  132.  
  133.    |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||}
  134.    {===================================================================
  135.    IF CHANGED
  136.    ===================================================================}
  137. procedure SaveEdModified ;
  138. var
  139.    Count                     : byte ;
  140.    {-------------------------------------------------------------------
  141.    -------------------------------------------------------------------}
  142. procedure DoThis ( P : PView ) ; FAR ;
  143. begin
  144.    if TypeOf ( P^ ) <> TypeOf ( TEditWindow ) then EXIT ;
  145.    with PEDITWINDOW ( P )^.Editor^ do
  146.    begin
  147.       if not Modified then EXIT ;
  148.       SetBorder ( 14 ) ;                              { YELLOW - busy }
  149.       Save ;
  150.       inc ( Count ) ;
  151.    end ;
  152. end ;
  153.    {- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  154.    PROCESS
  155.    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -}
  156. begin
  157.    Count                     := 0 ;
  158.    Desktop^.ForEach ( @DoThis ) ;
  159.    if Count > 0 then
  160.       SetBorder ( 0 ) ;                                { BLACK - done }
  161. end ;
  162.    {===================================================================
  163.  
  164.    ALWAYS A DIALOG FOR NAME
  165.  
  166.    ===================================================================}
  167. procedure SaveEdUntitled ;
  168.    {-------------------------------------------------------------------
  169.    -------------------------------------------------------------------}
  170. procedure DoThis ( P : PView ) ; FAR ;
  171. begin
  172.    if TypeOf ( P^ ) <> TypeOf ( TEditWindow ) then EXIT ;
  173.    with PEDITWINDOW ( P )^.Editor^ do
  174.    begin
  175.       if not Modified then EXIT ;
  176.       if FileName <> '' then EXIT ;
  177.       P^.MakeFirst ;                                 { bring to front }
  178.       SaveAs ;
  179.    end ;
  180. end ;
  181.    {- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  182.    PROCESS
  183.    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -}
  184. begin
  185.    Desktop^.ForEach ( @DoThis ) ;
  186. end ;
  187.    {===================================================================
  188.  
  189.    CLOSE - "Untitled" TEditWindow(s).  Must force "Modified" flag,
  190.    since cmClose won't work if ^. Valid returns FALSE.
  191.  
  192.    ===================================================================}
  193. procedure CloseEdUntitled ;
  194.    {-------------------------------------------------------------------
  195.    -------------------------------------------------------------------}
  196. procedure DoThis ( P : PView ) ; FAR ;
  197. begin
  198.    if TypeOf ( P^ ) <> TypeOf ( TEditWindow ) then EXIT ;
  199.    with PEDITWINDOW ( P )^.Editor^ do
  200.    begin
  201.       if FileName <> '' then EXIT ;
  202.       Modified               := FALSE ;
  203.    end ;
  204.    Message ( P , evCommand , cmClose , NIL ) ;
  205. end ;
  206.    {- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  207.    PROCESS
  208.    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -}
  209. begin
  210.    Desktop^.ForEach ( @DoThis ) ;
  211. end ;
  212.    {|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  213.  
  214.    CLIP BOARD
  215.  
  216.    |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||}
  217.    {===================================================================
  218.  
  219.    CREATE
  220.  
  221.    ===================================================================}
  222. procedure CreateClipboard ;
  223. var
  224.    R                         : TRect ;
  225. begin
  226.    if not BuffersInUse then EXIT ;
  227.    ClipWindow                := OpenEditor ( '' , FALSE ) ;
  228.    if ClipWindow = NIL then EXIT ;
  229.    Clipboard                 := ClipWindow^.Editor ;
  230.    Clipboard^.CanUndo        := FALSE ;
  231.    ClipWindow^.HelpCtx       := SaveCl